//
//  UIView+MB.h
//  Pods
//
//  Created by Catch on 16/5/12.
//
//

#import <UIKit/UIKit.h>

typedef void (^MBTappedBlock)();

/**
 *  UIView常用扩展类
 *  包括:Shortcut、viewController、Image、shadow、cornerRadius、load、tap、others
 */
@interface UIView (MB) <UIGestureRecognizerDelegate>

#pragma mark -- Shortcut

//frame.origin.x
@property (nonatomic) CGFloat left;
//frame.origin.y
@property (nonatomic) CGFloat top;
//frame.origin.x + frame.size.width
@property (nonatomic) CGFloat right;
//frame.origin.y + frame.size.height
@property (nonatomic) CGFloat bottom;
//frame.size.width
@property (nonatomic) CGFloat width;
//frame.size.height
@property (nonatomic) CGFloat height;
//center.x
@property (nonatomic) CGFloat centerX;
//center.y
@property (nonatomic) CGFloat centerY;
//frame.origin
@property (nonatomic) CGPoint origin;
//frame.size
@property (nonatomic) CGSize  size;


#pragma mark -- viewController

//获取视图控制器（可能返回nil）
@property (nullable, nonatomic, readonly) UIViewController *viewController;


#pragma mark -- Image

/**
 *  截图
 *
 *  @return UIImage
 */
- (nullable UIImage *)snapshotImage;

/**
 *  截图
 *
 *  @param afterUpdates 是否等待视图更新完毕
 *
 *  @return UIImage
 */
- (nullable UIImage *)snapshotImageAfterScreenUpdates:(BOOL)afterUpdates;

/**
 *  截图成PDF
 *
 *  @return pdf NSData
 */
- (nullable NSData *)snapshotPDF;


#pragma mark -- shadow

/**
 *  设置阴影
 *
 *  @param color  Shadow Color
 *  @param offset Shadow offset
 *  @param radius Shadow radius
 */
- (void)setLayerShadow:(nullable UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius;

#pragma mark -- cornerRadius

/**
 *  设置圆角
 *
 *  @param cornerRadius CornerRadius
 */
-(void)setLayerCornerRadius:(CGFloat)cornerRadius;

#pragma mark -- load

/**
 *  从XIB初始化
 *
 *  @return UIView
 */
+(nullable id)loadFromXib;


#pragma mark -- tap

/**
 *  单击事件
 *
 *  @param block 回调
 */
- (void)whenTapped:(nullable MBTappedBlock)block;

/**
 *  双击事件
 *
 *  @param block 回调
 */
- (void)whenDoubleTapped:(nullable MBTappedBlock)block;

/**
 *  双指点击
 *
 *  @param block 回调
 */
- (void)whenTwoFingerTapped:(nullable MBTappedBlock)block;

/**
 *  按下
 *
 *  @param block 回调
 */
- (void)whenTouchedDown:(nullable MBTappedBlock)block;

/**
 *  弹起
 *
 *  @param block 回调
 */
- (void)whenTouchedUp:(nullable MBTappedBlock)block;

#pragma mark -- others

/**
 *  移除所有子视图
 *  @warning 千万别再 view's drawRect: 方法中调用
 */
- (void)removeAllSubviews;

@end